package com.aatrox.bhsypro.controller;

import com.aatrox.bhsypro.entity.BUser;
import com.aatrox.bhsypro.entity.BVideo;
import com.aatrox.bhsypro.entity.BhSyGos;
import com.aatrox.bhsypro.entity.LikeVideo;
import com.aatrox.bhsypro.service.BVideoService;
import com.aatrox.bhsypro.util.CookieUtil;
import com.aatrox.bhsypro.util.JsonResult;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

/**
 * 视频 ajax
 */
@Controller
public class BVideoAjaxController {
    @Autowired
    BVideoService bVideoService;
    @RequestMapping("/ship/{l}/{p}")
    public String sel(ModelMap map,@PathVariable("p") int p,@PathVariable("l") String l){
        System.out.println("p"+p);
        List list=bVideoService.fy(p);
        System.out.println("list"+list);
        //分页类
        PageInfo page =  bVideoService.sel(p);
        if(page.getPages()==0){
            page.setPages(1);
        }
        System.out.println("dq"+page.getPageNum());

        map.put("url","ship");
        map.put("page",page);
        map.put("list",list);
        return "txt/BVideo";
    }

    //分类查询
    @RequestMapping("/likesel/{l}/{p}")
    public String likesel(ModelMap map,@PathVariable("l") String l,@PathVariable("p") int p){
        List list=bVideoService.likesel(l,p);
        System.out.println("list"+list);
        //分页类
        PageInfo page=bVideoService.likefy(new LikeVideo(l,p));
        if(page.getPages()==0){
            page.setPages(1);
        }

        map.put("url","likesel");
        map.put("l",l);
        map.put("page",page);
        map.put("list",list);
        return "txt/BVideo";
    }




    @Autowired
    RedisTemplate<String,Object> redisTemplate;
    //查询播放量最多的5个（看自己的
    @ResponseBody
    @RequestMapping(value = "/Bvsel",method = RequestMethod.POST)
    public JsonResult Bvsel(HttpServletRequest request,HttpSession session){
        String ticket = CookieUtil.getCookieValue(request,"userTicket");
        BUser user = (BUser) redisTemplate.opsForValue().get("user:"+ticket+"uid:"+(session.getAttribute("buserId")));
        System.out.println("controller--"+user.getUid());
        HashMap hm = new HashMap();
        List bv = (List) bVideoService.BvSel(user.getUid());

        hm.put("bv",bv);

        return new JsonResult(200,"成功",hm);

    }


}
